package com.kfm.servlet;

import com.kfm.util.Contains;

import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;
import java.io.File;
import java.io.IOException;
import java.util.Collection;

@WebServlet("/multipart")
@MultipartConfig // 支持文件上传
public class MultipartServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

//        Part f1 = request.getPart("f1");
//        Part f2 = request.getPart("f2");
//
//        f1.write(Contains.FILE_PATH + File.separator + "a.jpg");
//        f2.write(Contains.FILE_PATH + File.separator + "b.jpg");

        Collection<Part> parts = request.getParts();

        // TODO (多文件上传)
//        for (Part part : parts){
//
//        }


    }
}
